package charpter14.lynx;

import java.util.Arrays;
import java.util.List;

abstract class Shape {
	void draw() {
		if (flag){
			System.out.println("Highlighted " + this + ".draw()");
		}else{
			System.out.println(this + ".draw()");
		}
	}

	void rotate() {
		if (flag){
			System.out.println("Highlighted " + ".rotate()");
		}else{
			System.out.println(this + ".rotate()");
		}
	}
	
	private boolean flag = false;

	abstract public String toString();

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}
}

class Circle extends Shape {
	public String toString() {
		return "Circle";
	}
}

class Square extends Shape {
	public String toString() {
		return "Square";
	}
}

class Triangle extends Shape {
	public String toString() {
		return "Triangle";
	}
}

class Rhomboid extends Shape {

	@Override
	public String toString() {
		return "Rhomboid";
	}

}

public class Three {
	public static void main(String[] args) {
		List<Shape> shapeList = Arrays.asList(new Circle(), new Square(),
				new Triangle(), new Rhomboid());
		for (Shape shape : shapeList)
			((Rhomboid) shape).draw();
	}
}
//
// Exception in thread "main" java.lang.ClassCastException:
// charpter14.lynx.Circle
// cannot be cast to charpter14.lynx.Rhomboid
// at charpter14.lynx.Three.main(Three.java:46)